package com.jichangxiu.server.platform.action;

import cn.hutool.core.collection.ListUtil;
import com.jichangxiu.common.annotation.*;
import com.jichangxiu.common.entity.bo.PageData;
import com.jichangxiu.framework.action.BaseAction;
import com.jichangxiu.server.platform.entity.dto.PlatformDictDataQueryDto;
import com.jichangxiu.server.platform.entity.vo.PlatformDictDataAddVo;
import com.jichangxiu.server.platform.entity.vo.PlatformDictDataEditVo;
import com.jichangxiu.server.platform.entity.vo.PlatformDictDataQueryVo;
import com.jichangxiu.server.platform.service.PlatformDictDataService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;

/**
 * PlatformDictDataAction:
 * 平台-字典值管理控制器
 *
 * @author Jcx
 * @create 2023-02-25 22:10
 */
@Slf4j
@Rest("/platform/dict/data")
@Tag(name = "平台-字典值管理控制器")
public class PlatformDictDataAction extends BaseAction {

    @Resource
    private PlatformDictDataService platformDictDataService;

    /**
     * 新增字典值
     *
     * @param platformDictDataAddVo 字典值视图对象
     * @return 是否成功
     */
    @Post("/add")
    @Operation(summary = "平台-新增字典值")
    @PreAuthorize("@ss.hasPermission('platform:dictData:add')")
    public String add(@RequestBody PlatformDictDataAddVo platformDictDataAddVo) {
        return toStr(platformDictDataService.add(platformDictDataAddVo));
    }

    /**
     * 多选级联删除字典值
     *
     * @param dataIds 字典值ID列表
     * @return 是否成功
     */
    @Delete("/del")
    @Operation(summary = "平台-多选级联删除字典值")
    @PreAuthorize("@ss.hasPermission('platform:dictData:del')")
    public String del(@RequestBody String[] dataIds) {
        return toStr(platformDictDataService.del(ListUtil.toList(dataIds)));
    }

    /**
     * 修改字典值信息
     *
     * @param platformDictDataEditVo 字典值视图对象
     * @return 是否成功
     */
    @Put("/edit")
    @Operation(summary = "平台-修改字典值信息")
    @PreAuthorize("@ss.hasPermission('platform:dictData:edit')")
    public String edit(@RequestBody PlatformDictDataEditVo platformDictDataEditVo) {
        return toStr(platformDictDataService.edit(platformDictDataEditVo));
    }

    /**
     * 根据ID获取字典值详情
     *
     * @param dataId 字典值ID
     * @return 字典类型详情
     */
    @Get("/info/{dataId}")
    @Operation(summary = "平台-根据ID获取字典值详情")
    @PreAuthorize("@ss.hasPermission('platform:dictData:info')")
    public PlatformDictDataQueryDto info(@PathVariable("dataId") @NotBlank(message = "字典情ID不能为空") String dataId) {
        return platformDictDataService.info(dataId);
    }

    /**
     * 分页查询字典值列表
     *
     * @param platformDictDataQueryVo 字典值视图对象
     * @return 分页字典值列表
     */
    @Get("/pageList")
    @Operation(summary = "平台-分页查询字典值列表")
    @PreAuthorize("@ss.hasPermission('platform:dictData:pageList')")
    public PageData<PlatformDictDataQueryDto> pageList(@ParameterObject PlatformDictDataQueryVo platformDictDataQueryVo) {
        return platformDictDataService.pageList(platformDictDataQueryVo);
    }

}

